#include <iostream>
#include <string.h>
using namespace std;
class Computer{
private:
    char * _brand;
    double _price;

public:
    //构造函数
    Computer(const char * brand, double price)
        :_brand(new char[strlen(brand) + 1]())
         ,_price(price)
    {
        strcpy(_brand, brand);
        cout << "constructor: " << _brand << endl;
    }

    Computer(const Computer & rhs)
        : _brand(new char[strlen(rhs._brand) + 1]())
          , _price(rhs._price)
    {
        cout<<"copy"<<endl;
        strcpy(_brand, rhs._brand);
    }

    //析构函数
    ~Computer(){
        cout << "~~~brand=" << _brand << " price=" << _price << endl;
        if(_brand != NULL){
            delete [] _brand;
            _brand = NULL;
        }
    }

    void print(void){
        cout<<_brand<<" : "<<_price<<endl;
    }

};
//全局对象

void test(){
    Computer pp("nihao",3);
//    Computer &cc = Computer("hello",30);
//    cc.print();
}

int main()
{
    test();

    return 0;
}
